package com.client;

import com.notowania.*;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;

public class ConsumerSpolki {
 
    
	public void consumeMessage(String queueName){
     	  
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        try{
            Connection connection = connectionFactory.createConnection();
            connection.start();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            Destination queue = session.createQueue(queueName);
            MessageConsumer consumer = session.createConsumer(queue);
           
            System.out.println("Consumer waiting...");

      Message message = consumer.receive();
  			
            if(message instanceof ObjectMessage){
        ObjectMessage message2 = (ObjectMessage)consumer.receive();
                Notowania notow = (Notowania)message2.getObject();
                 String nazwa = notow.getNazwa();
        		   setNazwa(nazwa);
            }          

            consumer.close();
            session.close();
            connection.close();
        }catch(JMSException e){         
            System.out.println("Problem creating connection to ActiveMQ");
            e.printStackTrace();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
	String Nazwa;

    public String getNazwa() {
        return Nazwa;
    }
    public void setNazwa(String Nazwa) {
        this.Nazwa = Nazwa;
    }
  } 